package com.xyzk.diagnose.activity.adapter;

import java.util.List;
import java.util.Map;

import com.xyzk.diagnose.R;
import com.xyzk.diagnose.tools.DbAdapter.TableMain;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SettingQueryAdapter extends BaseAdapter{
	private List<Map<String, String>> uplist;
	private Context context;
	public SettingQueryAdapter(Context context, List<Map<String, String>> data){
		this.context = context;
		uplist = data;
	}
	@Override
	public int getCount() {
		return uplist == null ? -1 : uplist.size();
	}

	@Override
	public Object getItem(int position) {
		return uplist == null ? -1 : uplist.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		ViewHold vh;
		if(view == null){
			vh = new ViewHold();
			view = View.inflate(context, R.layout.activity_setting_query_item, null);
			vh.tvId = (TextView) view.findViewById(R.id.tv_query_id);
			vh.tvVIN = (TextView) view.findViewById(R.id.tv_query_vin);
			vh.tvCar = (TextView) view.findViewById(R.id.tv_query_car);
			vh.tvStation = (TextView) view.findViewById(R.id.tv_query_station);
			vh.tvResult = (TextView) view.findViewById(R.id.tv_query_result);
			vh.tvWeb = (TextView) view.findViewById(R.id.tv_query_WEB);
			vh.tvDate = (TextView) view.findViewById(R.id.tv_query_date);
			view.setTag(vh);
		}else {
			vh = (ViewHold) view.getTag();
		}
		vh.tvId.setText(String.valueOf(position+1));
		Map<String, String> map = uplist.get(position);
		vh.tvVIN.setText(map.get(TableMain.vin));
		vh.tvCar.setText(map.get(TableMain.car));
		vh.tvStation.setText(map.get(TableMain.carstation));
		vh.tvDate.setText(map.get(TableMain.timestart));
		vh.tvWeb.setText(map.get(TableMain.update));
		vh.tvResult.setText(map.get(TableMain.result));
		return view;
	}

	class ViewHold{
		TextView tvId;
		TextView tvVIN;
		TextView tvCar;
		TextView tvStation;
		TextView tvWeb;
		TextView tvDate;
		TextView tvResult;
	}
}
